package com.star.util.common;

import java.io.Serializable;
import java.util.List;

public class Page implements Serializable {

	private static final long serialVersionUID = 1L;

	public static final int DEFAUTSIZE = 10;

	// 每页记录数，要改成从属性文件中读取

	private int pageSize = 5;

	// 总记录数

	private long totalCount;

	// 当前页

	private int pageNum = 1;

	// 总页数

	private int pageCount;

	// 记录

	private List<?> data;

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public long getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(Long totalCount) {
		if (totalCount <= 0)
			this.totalCount = 0;
		else {
			this.totalCount = totalCount;
			if (this.totalCount % pageSize == 0)
				setPageCount((int) this.totalCount / pageSize);
			else
				setPageCount((int) (this.totalCount / pageSize + 1));
		}
	}

	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		if (pageCount <= 0)
			this.pageCount = 0;
		else
			this.pageCount = pageCount;
	}

	public int getBeginIndex() {
		if (pageNum < 1)
			return 0;
		else if (pageNum > pageCount)
			return (pageCount - 1) * pageSize;
		else
			return (pageNum - 1) * pageSize;
	}

	public int getEndIndex() {
		return (getBeginIndex() + pageSize);
	}

	public List<?> getData() {
		return data;
	}

	public void setData(List<?> data) {
		this.data = data;
	}
}